home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / edit.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  7KB  |  194 lines

  1. /***********************************************************************/
  2. /* EDIT.C - The body of the program.                                   */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1995 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Id: edit.c 2.0 1995/01/26 16:30:53 MH Release MH $
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <time.h>
  45.  
  46. #include "the.h"
  47. #include "proto.h"
  48.  
  49. /*#define TRACE*/
  50.  bool prefix_changed=FALSE;
  51. /***********************************************************************/
  52. #ifdef PROTO
  53. void editor(void)
  54. #else
  55. void editor()
  56. #endif
  57. /***********************************************************************/
  58. {
  59. /*-------------------------- external data ----------------------------*/
  60.  extern VIEW_DETAILS *vd_first;
  61.  extern short file_start;
  62.  extern CHARTYPE *dirfilename;
  63.  extern bool error_on_screen;
  64.  extern CHARTYPE file_disposition;
  65.  extern CHARTYPE number_of_files;
  66.  extern WINDOW *foot,*error_window;
  67. /*--------------------------- local data ------------------------------*/
  68.  int key=0;
  69.  unsigned short x=0,y=0;
  70.  short rc=RC_OK;
  71.  CHARTYPE string_key[2];
  72.  VIEW_DETAILS *save_vd=vd_current;
  73. /*--------------------------- processing ------------------------------*/
  74. #ifdef TRACE
  75.  trace_function("edit.c:    editor");
  76. #endif
  77. /*---------------------------------------------------------------------*/
  78. /* For each view, calculate the current_row value. This has to be done */
  79. /* AFTER initscr() so that the size of the filearea is known.          */
  80. /*---------------------------------------------------------------------*/
  81.  CURRENT_VIEW = vd_first;
  82.  do
  83.    {
  84.     CURRENT_VIEW->current_row = calculate_actual_row(CURRENT_VIEW->current_base,
  85.                                                      CURRENT_VIEW->current_off,
  86.                                                      CURRENT_SCREEN.rows[WINDOW_MAIN]);
  87.     CURRENT_VIEW = NEXT_VIEW;
  88.    }
  89.  while(CURRENT_VIEW);
  90.  CURRENT_VIEW = save_vd;
  91. /*---------------------------------------------------------------------*/
  92. /* whoutrefresh() is called here so that the first call to getch() on  */
  93. /* stdscr does not clear the screen.                                   */
  94. /*---------------------------------------------------------------------*/
  95.  wnoutrefresh(stdscr);
  96.  
  97.  if (CURRENT_WINDOW_ARROW != (WINDOW *)NULL)
  98.    {
  99.     touchwin(CURRENT_WINDOW_ARROW);
  100.     wnoutrefresh(CURRENT_WINDOW_ARROW);
  101.    }
  102. /*---------------------------------------------------------------------*/
  103. /* Put the cursor into the column between file time and file name for  */
  104. /* the special DIR.DIR file.                                           */
  105. /*---------------------------------------------------------------------*/
  106.  if (strcmp(CURRENT_FILE->fname,dirfilename) == 0)
  107.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,file_start-1);
  108.  else
  109.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,0);
  110. /*---------------------------------------------------------------------*/
  111. /* Display the current view(s)...                                      */
  112. /*---------------------------------------------------------------------*/
  113.  build_current_screen(); 
  114.  display_current_screen();
  115.  show_footing();
  116.  if (CURRENT_WINDOW_PREFIX != NULL)
  117.     wnoutrefresh(CURRENT_WINDOW_PREFIX);
  118.  if (CURRENT_WINDOW_COMMAND != (WINDOW *)NULL)
  119.    {
  120.     wmove(CURRENT_WINDOW_COMMAND,0,0);
  121.     touchwin(CURRENT_WINDOW_COMMAND);
  122.     wnoutrefresh(CURRENT_WINDOW_COMMAND);
  123.    }
  124.  if (file_disposition != FILE_NORMAL)
  125.    {
  126.     switch(file_disposition)
  127.       {
  128.        case FILE_NEW:
  129.                           display_error(0,(CHARTYPE *)"New File...",TRUE);
  130.                           break;
  131.        case FILE_READONLY:
  132.                           display_error(0,(CHARTYPE *)"File is read-only...",FALSE);
  133.                           break;
  134.        default:
  135.                           break;
  136.       }
  137. /*    wnoutrefresh(error_window);*/
  138.    }
  139.  wrefresh(CURRENT_WINDOW);
  140.  
  141.  while (1)
  142.    {
  143. #if defined(USE_EXTCURSES)
  144.     getyx(CURRENT_WINDOW,y,x);
  145.     wmove(CURRENT_WINDOW,y,x);
  146.     wrefresh(CURRENT_WINDOW);
  147. #endif
  148.     key = my_getch(stdscr);
  149.     if (error_on_screen)
  150.        clear_msgline();
  151.     rc = function_key(key);
  152.     if (number_of_files == 0)
  153.        break;
  154.     if (rc >= RAW_KEY)
  155.       {
  156.        if (rc > RAW_KEY)
  157.           key = rc - (RAW_KEY*2);
  158.        if (key < 256 && key >= 0)
  159.          {
  160.           string_key[0] = (CHARTYPE)key;
  161.           string_key[1] = '\0';
  162.           (void)Text(string_key);
  163.          }
  164.       }
  165.     show_footing();
  166. #if 0
  167.     if (CURRENT_VIEW->focus_line == CURRENT_VIEW->current_line
  168.     &&  CURRENT_VIEW->hexshow_on
  169.     &&  CURRENT_VIEW->current_window == WINDOW_MAIN)
  170.       {
  171.        getyx(CURRENT_WINDOW_MAIN,y,x);
  172.        build_current_screen(); 
  173.        display_current_screen();
  174.        wmove(CURRENT_WINDOW_MAIN,y,x);
  175.       }
  176. #endif
  177.  
  178.     refresh_current_screen();
  179.     if (error_on_screen)
  180.       {
  181.        getyx(CURRENT_WINDOW,y,x);
  182.        touchwin(error_window);
  183.        wnoutrefresh(error_window);
  184.        wmove(CURRENT_WINDOW,y,x);
  185.        wnoutrefresh(CURRENT_WINDOW);
  186.       }
  187.     doupdate();
  188.    }
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return;
  193. }
  194.